<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="~{common/header :: commonHead}"></head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight"
     th:with="page=${pageObj.page},size=${pageObj.pageSize},total=${pageObj.total},totalPage=${pageObj.totalPage},keyword=${pageObj.keyword},fromDate=${pageObj.fromDate},toDate=${pageObj.toDate},couponName=${pageObj.couponName}">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5> 停车券使用列表</h5>
                    <div class="ibox-tools">
                        <shiro:hasPermission name="export_parking">
                            <a th:href="${'/parking/export?total='+total+'&keyword='+(keyword==null?'':keyword)+'&fromDate='+(fromDate==null?'':fromDate)+'&toDate='+(toDate==null?'':toDate)+'&couponName='+(couponName==null?'':couponName)}" title="导出数据"><i class="glyphicon glyphicon-export"></i></a>
                        </shiro:hasPermission>
                        <a href="javascript: window.location.href='/parking/list';" title="刷新"><i
                                class="glyphicon glyphicon-repeat"></i></a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div id="editable_wrapper" class="dataTables_wrapper form-inline" role="grid">
                        <div class="row">
                            <div class="col-sm-4">
                                <div class="dataTables_length" id="editable_length"><label>每页
                                    <select name="editable_length" aria-controls="editable"
                                            class="form-control input-sm" id="page_size_selector">
                                        <option th:selected="${size eq 5}" value="5">5</option>
                                        <option th:selected="${size eq 10}" value="10">10</option>
                                        <option th:selected="${size eq 25}" value="25">25</option>
                                        <option th:selected="${size eq 50}" value="50">50</option>
                                        <option th:selected="${size eq 100}" value="100">100</option>
                                    </select> 条记录</label>
                                </div>
                            </div>
                            <div class="col-sm-2">
                                <select id="couponName" class="chosen-select form-control m-b">
                                    <option th:selected="${pageObj.couponName eq ''}" value="">请选择停车券类型</option>
                                    <option th:selected="${pageObj.couponName eq '1a576fcb722b4f5a8f8d8940ee4e699b'}" value="1a576fcb722b4f5a8f8d8940ee4e699b">etcp3元停车券</option>
                                    <option th:selected="${pageObj.couponName eq '6fb9743c2bcf431c94d87eeae0739c85'}" value="6fb9743c2bcf431c94d87eeae0739c85">etcp6元停车券</option>
                                    <option th:selected="${pageObj.couponName eq 'fcf4eab81f6143059f5642df2c00649e'}" value="fcf4eab81f6143059f5642df2c00649e">etcp9元停车券</option>
                                    <option th:selected="${pageObj.couponName eq '2230641ed29746d8aed7d045151eb969'}" value="2230641ed29746d8aed7d045151eb969">etcp12元停车券</option>
                                </select>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-daterange input-group" id="datepicker">
                                    <input type="text" class="input-sm form-control" name="start" id="start_date" placeholder="开始时间" autocomplete="off" th:value="${fromDate} ">
                                    <span class="input-group-addon">到</span>
                                    <input type="text" class="input-sm form-control" name="end" id="end_date" placeholder="结束时间" autocomplete="off" th:value="${toDate}">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group" style="float: right">
                                    <input th:value="${keyword}" type="text" placeholder="请输入关键词" class="input-sm form-control" id="search_bar">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-primary" id="search-btn"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <table class="table table-striped table-bordered table-hover  dataTable" id="editable"
                               aria-describedby="editable_info">
                            <thead>
                            <tr role="row">
                                <th aria-label="会员车牌号" style="width: 8%;">会员车牌号</th>
                                <th aria-label="会员名称" style="width: 8%;">会员名称</th>
                                <th aria-label="手机号" style="width: 8%;">手机号</th>
                                <th aria-label="会员卡号" style="width: 8%;">会员卡号</th>
                                <th aria-label="优惠券名称" style="width: 15%;">优惠券名称</th>
                                <th aria-label="优惠券券码" style="width: 15%;">优惠券券码</th>
                                <th aria-label="优惠券领取时间" style="width: 10%;">优惠券领取时间</th>
                                <th aria-label="优惠券使用时间" style="width: 10%;">优惠券使用时间</th>
                                <th aria-label="优惠券使用时间" style="width: 10%;">优惠券有效时间</th>
                                <th aria-label="优惠券使用时间" style="width: 10%;">优惠券过期时间</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="gradeA odd" th:if="${#lists.isEmpty(pageObj.list)}">
                                <td colspan="9" style="text-align: center">
                                    没有数据o&gt;^&lt;o
                                </td>
                            </tr>
                            <tr class="gradeA odd" th:each="item : ${pageObj.list}">
                                <td th:with="carNumber=${item.carNumber}" th:utext="${null == keyword ? carNumber : #strings.replace(carNumber,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                <td th:with="useName=${item.useName}" th:utext="${null == keyword ? useName : #strings.replace(useName,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                <td th:with="phone=${item.phone}" th:utext="${null == keyword ? phone : #strings.replace(phone,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                <td th:with="useMemberCard=${item.useMemberCard}" th:utext="${null == keyword ? useMemberCard : #strings.replace(useMemberCard,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                <td th:text="${item.couponName}"></td>
                                <td th:text="${item.couponCode}"></td>
                                <td th:text="${item.addTime}"></td>
                                <td th:text="${item.useTime}"></td>
                                <td th:text="${item.useTimeStart}"></td>
                                <td th:text="${item.useTimeEnd}"></td>


                            </tr>
                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" role="alert" aria-live="polite" aria-relevant="all"
                                     th:text="${'显示 '
                                      + (page * size + 1)
                                      + ' 到 '
                                      + ((page+1) lt totalPage ? (size + page * size) : (total % size == 0 ? total : (total % size + size * page)))
                                      + ' 项，共 '
                                      + total + ' 项 ' + totalPage + ' 页'}">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers">
                                    <ul class="pagination" th:if="${totalPage>0}">
                                        <li th:class="${page==0}?'paginate_button previous disabled':'paginate_button previous'">
                                            <a th:href="${(page==0)?'#':'/parking/list?page='+page
                                             +'&pageSize='+size
                                             +'&keyword='+(null==keyword?'':keyword)
                                             +'&fromDate='+(null==fromDate?'':fromDate)
                                             +'&couponName='+(null==couponName?'':couponName)
                                             +'&toDate='+(null==toDate?'':toDate)}">上一页</a>
                                        </li>
                                        <li th:if="${totalPage<10}" th:each="i:${#numbers.sequence(1,totalPage)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/parking/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&couponName='+(null==couponName?'':couponName)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page<4&&totalPage>=9}" th:each="i:${#numbers.sequence(1,9)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/parking/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&couponName='+(null==couponName?'':couponName)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page>=4&&totalPage>=9&&page+5<totalPage}"
                                            th:each="i:${#numbers.sequence(page - 3,page + 5)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/parking/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&couponName='+(null==couponName?'':couponName)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page>=4&&totalPage>=9&&page+5>=totalPage}"
                                            th:each="i:${#numbers.sequence(totalPage - 8,totalPage)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/parking/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&couponName='+(null==couponName?'':couponName)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:class="${page+1==totalPage||totalPage<1}?'paginate_button next disabled':'paginate_button next'">
                                            <a th:href="${(page+1==totalPage||totalPage<1) ? '#' : '/parking/list?page='+(page+2)
                                             +'&pageSize='+size
                                             +'&keyword='+(null==keyword?'':keyword)
                                             +'&fromDate='+(null==fromDate?'':fromDate)
                                             +'&couponName='+(null==couponName?'':couponName)
                                             +'&toDate='+(null==toDate?'':toDate)}">下一页</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script th:inline="javascript">
    $("#page_size_selector").change(function () {
        let fromDate = $("#start_date").val();
        let toDate = $("#end_date").val();
        let selected = $(this).val();
        window.location.href = initUrl(0, selected, '', fromDate, toDate,'');
    })
    $("#search_bar").keydown(function (e) {
        let fromDate = $("#start_date").val();
        let toDate = $("#end_date").val();
        let couponName = $("#couponName").val();
        if (e.keyCode == 13) {
            let size = $("#page_size_selector").val();
            let keyword = $(this).val();
            window.location.href = initUrl(0, size, keyword, fromDate, toDate,couponName);
        }
    })

    $("#search-btn").click(function () {
        let fromDate = $("#start_date").val();
        let toDate = $("#end_date").val();
        let size = $("#page_size_selector").val();
        let keyword = $("#search_bar").val();
        let couponName = $("#couponName").val();

        window.location.href = initUrl(0, size, keyword, fromDate, toDate,couponName);
    })

    function initUrl(page, size, key, fromDate, toDate,couponName) {
        if (null == page) {
            page = 0;
        }
        return "/parking/list?page=" + page + "&pageSize=" + size + "&keyword=" + key + "&fromDate=" + fromDate + "&toDate=" + toDate+ "&couponName=" + couponName
    }
</script>
</html>